﻿/**
 * @file setting_bluetooth_ui.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_watch.h"

#if USE_LV_BLUETOOTH != 0

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/
static lv_obj_t * bluetooth_create(lv_obj_t * activity_obj);
static void bluetooth_prepare_destory(lv_obj_t * activity_obj);
static void bluetooth_back_img_event_cb(lv_obj_t * obj, lv_event_t e);
static lv_res_t bluetooth_switch_signal(lv_obj_t * sw, lv_signal_t sign, void * param);
static lv_obj_t * bluetooth_dev_list_create(lv_obj_t * par, uint16_t txtId, lv_event_cb_t rel_action);
static void bluetooth_dev_btn_action(lv_obj_t * btn, lv_event_t e);
static void bluetooth_availabel_list_btn_action(lv_obj_t * btn, lv_event_t e);
static void bluetooth_paired_list_btn_action(lv_obj_t * btn, lv_event_t e);
static void bluetooth_refresh_btn_action(lv_obj_t * btn, lv_event_t e);
//static lv_res_t bluetooth_mbox_action(lv_obj_t * btn, const char * txt);
static lv_obj_t * bluetooth_dev_list_add(lv_obj_t * list,  uint8_t state, char * name, lv_event_cb_t rel_action, uint32_t cod_type);
static void bluetooth_btn_style_init(lv_bluetooth_obj_ext_t * ext);
static void bluetooth_update_paired_label_show(void);
static nv_watch_bluetooth_t * bluetooth_read_nvm(void);
static void bluetooth_cancel_inquiry(void);
static lv_obj_t * bluetooth_processing_mbox_create(char * name, uint8_t process);
static void bluetooth_create_scan_dev_list(lv_obj_t * list);
static void bluetooth_create_paired_dev_list(lv_obj_t * list);
static void bluetooth_open_state_init(void);
static void bluetooth_create_scan_dev_list(lv_obj_t * list);
static void bluetooth_clean_scan_list(void);
static void bluetooth_receive_file_confirm_action(lv_obj_t * btnm, lv_event_t e);
static void bluetooth_transfer_file_finish_action(lv_obj_t * btnm, lv_event_t e);
static void bluetooth_tip_mbox_create(lv_obj_t * par);
static void bluetooth_sendfile_cancel_action(lv_obj_t * btn, lv_event_t e);
static void bluetooth_receive_abort_action(lv_obj_t * btnm, lv_event_t e);
/**********************
 *  STATIC VARIABLES
 **********************/
static lv_obj_t * bt_transfer_mbox = NULL;
static lv_signal_cb_t old_sw_signal;
static bool bt_setting_present = false;
/**********************
 *      MACROS
 **********************/
#define BT_OBEX_FILE_NAME_MAX_DISPLAY 33
/**********************
 *   GLOBAL FUNCTIONS
***********************/
void bluetooth_create_btn_action(lv_obj_t * btn, lv_event_t e)
{
    (void)btn;

    if(LV_EVENT_CLICKED != e) return;

    lv_watch_png_cache_all_free();
    lv_obj_t * obj = bluetooth_create(NULL);
    LV_ASSERT_MEM(obj);
}

lv_bluetooth_obj_ext_t * bluetooth_get_ext(void)
{
    lv_obj_t * activity_obj = lv_watch_get_activity_obj(ACT_ID_BLUETOOTH);
    if(activity_obj == NULL) return NULL;

    lv_obj_t * watch_obj;
    lv_watch_get_child_obj(activity_obj, lv_watch_obj_signal, &watch_obj);
    if(watch_obj == NULL) return NULL;

    if(watch_obj) {
        lv_bluetooth_obj_ext_t  * ext = lv_obj_get_ext_attr(watch_obj);
        return ext;
    }
    return NULL;
}

void bluetooth_show_object(bool state)
{
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    if(NULL == ext) return;
    if(state) {
        lv_obj_set_hidden(ext->opening_label, state);
        lv_switch_on(ext->sw, LV_ANIM_OFF);
    }
    lv_obj_set_hidden(lv_obj_get_parent(ext->paired_label), !state);
    lv_obj_set_hidden(lv_obj_get_parent(ext->available_label), !state);
    lv_obj_set_hidden(ext->refresh_btn, !state);
    if(state) {
        bluetooth_refresh_btn_action(ext->refresh_btn, LV_EVENT_CLICKED);
    }
}

void bluetooth_nvm_save_switch_state(bool state)
{
    nv_watch_bluetooth_t * nvm = bluetooth_read_nvm();
    nvm->on_off = state;
    UI_NV_Write_Req(NV_SECTION_UI_BLUETOOTH, 0, sizeof(nv_watch_bluetooth_t), (uint8_t *)nvm);
    lv_mem_free(nvm);
}

bool bluetooth_setting_is_active(void)
{
    if(bt_setting_present)
        return true;
    else
        return false;
}

void bluetooth_update_scan_label_show(void)
{
    char str[20];
    memset(str, 0, 20);
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    if(NULL == ext) return;
    if(bt_get_scan_dev_cnt() == 0)
        lv_label_set_text_id(ext->available_label, WATCH_TEXT_ID_AVAILABLE_DEV);
    else {
        if(lv_obj_get_base_dir(ext->available_label) == LV_BIDI_DIR_RTL)
            snprintf(str, 20, "(%d)%s",  bt_get_scan_dev_cnt(), (char *)lv_lang_get_text(WATCH_TEXT_ID_AVAILABLE_DEV));
        else
            snprintf(str, 20, "%s(%d)", (char *)lv_lang_get_text(WATCH_TEXT_ID_AVAILABLE_DEV), bt_get_scan_dev_cnt());
        lv_label_set_text(ext->available_label, str);
    }
}

void bluetooth_stop_scaning_anim(void)
{
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    if(NULL == ext) return;
    if(ext->preload) {
        lv_obj_del(ext->preload);
        ext->preload = NULL;
        lv_obj_set_hidden(lv_obj_get_child(ext->refresh_btn, NULL), false);
        lv_btn_set_state(ext->refresh_btn, LV_BTN_STATE_RELEASED);
    }
    watch_set_suspend_enable(true, ACT_ID_BLUETOOTH, 0);
}

void bluetooth_update_display(void)
{
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    if(NULL == ext) return;
    if(ext->mbox) {
        lv_obj_del(ext->mbox);
        ext->mbox = NULL;
    }
    if(ext->dev_list) {
        uint16_t txtid = lv_obj_get_user_data(ext->title_label).user_num;
        if(txtid == WATCH_TEXT_ID_AVAILABLE_DEV) {
            if(bt_get_scan_dev_cnt() == 0) {
                lv_obj_del(lv_obj_get_parent(ext->dev_list));
                bluetooth_update_scan_label_show();
                bluetooth_update_paired_label_show();
                ext->dev_list = NULL;
                ext->title_label = NULL;
                ext->mbox = NULL;
            } else {
                lv_list_clean(ext->dev_list);
                bluetooth_create_scan_dev_list(ext->dev_list);
            }
        } else if(txtid == WATCH_TEXT_ID_PAIRED_DEV) {
            if(bt_get_paired_dev_cnt() == 0) {
                lv_obj_del(lv_obj_get_parent(ext->dev_list));
                bluetooth_update_scan_label_show();
                bluetooth_update_paired_label_show();
                ext->dev_list = NULL;
                ext->title_label = NULL;
                ext->mbox = NULL;
            } else {
                lv_list_clean(ext->dev_list);
                bluetooth_create_paired_dev_list(ext->dev_list);
            }
        }
    } else {
        bluetooth_update_paired_label_show();
        bluetooth_update_scan_label_show();
    }
}

void bluetooth_processing_mbox_update(void)
{
    if(bluetooth_setting_is_active()) {

        lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
        if(ext->mbox) {
            uint8_t process = lv_obj_get_user_data(ext->mbox).user_num;
            if(process == PROCESS_PAIR)
                lv_msgbox_set_text(ext->mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_PAIRED_FAILED));
            else if(process == PROCESS_CONNECT)
                lv_msgbox_set_text(ext->mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_CONNECT_FAILED));
            else if(process == PROCESS_UNPAIR)
                lv_msgbox_set_text(ext->mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_UNPAIR_FAILED));
            else
                lv_msgbox_set_text(ext->mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_DISCONNECT_FAILED));
            lv_obj_realign(ext->mbox);
            lv_msgbox_set_anim_time(ext->mbox, 0);
            lv_msgbox_start_auto_close(ext->mbox, 2000);
            ext->mbox = NULL;
        }
    } else {
        if(bt_transfer_mbox) {
            bluetooth_transfer_file_finish(lv_obj_get_user_data(bt_transfer_mbox).user_num, 0);
        }
    }
}

void bluetooth_paired_processing_mbox_update(void)
{
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    if(ext && ext->mbox) {
        uint8_t process = lv_watch_get_free_num(ext->mbox);
        if(process == PROCESS_PAIR){
            lv_msgbox_set_text(ext->mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_PAIRED_FAILED));
            lv_obj_realign(ext->mbox);
            lv_msgbox_set_anim_time(ext->mbox, 0);
            lv_msgbox_start_auto_close(ext->mbox, 2000);
            ext->mbox = NULL;
        }
    }
}

void bluetooth_paired_mbox_update(void)
{
    printf("%s:bt paired confirm timeout!!!\n", __FUNCTION__);
    lv_obj_del(lv_obj_get_parent(bt_transfer_mbox));
    bt_transfer_mbox = NULL;

    lv_obj_t * warn_box = lv_msgbox_create(lv_watch_get_top_activity_obj(), NULL);
    lv_obj_set_width(warn_box, LV_HOR_RES * 4 / 5);
    lv_msgbox_set_text(warn_box, (char *)lv_lang_get_text(WATCH_TEXT_ID_PAIRED_FAILED));
    lv_obj_realign(warn_box);
    lv_msgbox_set_anim_time(warn_box, 0);
    lv_msgbox_start_auto_close(warn_box, 2000);
}

void bluetooth_transfer_mbox_update(void)
{
    if(NULL == bt_transfer_mbox) return;
    if(lv_watch_get_free_num(bt_transfer_mbox) == PROCESS_PAIRED_CONFIRM) {
        bluetooth_paired_mbox_update();
        return;
    }
    lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(bt_transfer_mbox);
    if(ext->btnm && lv_obj_get_event_cb(ext->btnm) == bluetooth_transfer_file_finish_action) {
        printf("%s:bt transfer finished\n", __FUNCTION__);
        return;
    }
    printf("%s: bt_transfer doesn't finish, acl disconnect,so transfer failed!!!", __FUNCTION__);
    bluetooth_transfer_file_finish(lv_obj_get_user_data(bt_transfer_mbox).user_num, 0);
}

bool bluetooth_start_without_ui(void)
{
    bool ret = false;
    nv_watch_bluetooth_t * nvm = bluetooth_read_nvm();
    printf("bt nvm on_off = %d\n", nvm->on_off);
    if(nvm->on_off == 1) {
        bt_adp_task_create();
        bt_list_init();
        if(bt_open_device() == 0) {
            ret = true;
        }
    }
    lv_mem_free(nvm);

    return ret;
}

void bluetooth_transfer_file_process_update(bt_file_trans_process process)
{
    if(NULL == bt_transfer_mbox) return;
    lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(bt_transfer_mbox);
    if(ext->btnm) return;
    lv_obj_t * bar = lv_obj_get_child(bt_transfer_mbox, NULL);
    if(NULL == bar) return;
    int16_t value = 0;
    if(PROCESS_RECV_FILE == process) {
        bt_file_receive_context * recv_file = bt_get_receive_file_info();
        value = recv_file->file_offset * 100 / recv_file->file_size;
    } else {
        bt_file_send_context * send_file = bt_get_send_file_info();
        value = send_file->file_offset * 100 / send_file->file_size;
    }
    printf("bt_file_tracfering value = %d\n", value);
    lv_bar_set_value(bar, value, LV_ANIM_OFF);
}

void bluetooth_receive_file_receive_process_finish_task(lv_task_t * task)
{
    printf("%s\n", __FUNCTION__);

    bluetooth_transfer_file_finish(PROCESS_RECV_FILE, 1);
}

void bluetooth_receive_file_process_update_and_finish(void)
{
    printf("%s: rcv the last data\n", __FUNCTION__);

    bluetooth_transfer_file_process_update(PROCESS_RECV_FILE);

    lv_task_t * task = lv_task_create(bluetooth_receive_file_receive_process_finish_task,
                                      100, LV_TASK_PRIO_HIGH, NULL);
    lv_task_once(task);
}

void bluetooth_receive_file_abort_tip(uint8_t reason)
{
    printf("bt check space tip reason = %d\n", reason);
    watch_wakeup_lcd(true);
    lv_obj_t * content = lv_cont_create(lv_watch_get_top_activity_obj(), NULL);
    lv_obj_set_size(content, LV_HOR_RES, LV_VER_RES);
    lv_obj_add_style(content, LV_CONT_PART_MAIN, &lv_watch_style_transp);
    lv_obj_t * tip_mbox = lv_msgbox_create(content, NULL);
    lv_obj_set_top(tip_mbox, true);
    lv_obj_set_width(tip_mbox, LV_HOR_RES * 4 / 5);
    if(BT_RECEIVE_NO_SDCARD == reason)
        lv_msgbox_set_text(tip_mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_NO_SDCARD));
    else if(BT_RECEIVE_NO_SPACE == reason)
        lv_msgbox_set_text(tip_mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_NO_SPACE));
    else
        lv_msgbox_set_text(tip_mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_SD_MOUNTED_AS_U_STORAGE));
    static const char * ok_txt[2];
    ok_txt[0] = (char *)lv_lang_get_text(WATCH_TEXT_ID_OK);
    ok_txt[1] = "";
    lv_msgbox_add_btns(tip_mbox, ok_txt);
    lv_obj_set_event_cb(lv_msgbox_get_btnmatrix(tip_mbox), bluetooth_receive_abort_action);
    lv_obj_realign(tip_mbox);
}

void bluetooth_transfer_file_finish(bt_file_trans_process process, uint8 success)
{
    watch_set_suspend_enable(true, ACT_ID_BLUETOOTH, 0);
    if(NULL == bt_transfer_mbox) return;

    if(process == PROCESS_PAIRED_CONFIRM) {
        bluetooth_paired_mbox_update();
        return;
    }
    lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(bt_transfer_mbox);
    if(ext->btnm) {
        lv_obj_del(ext->btnm);
        ext->btnm = NULL;
    } else if(lv_obj_count_children(bt_transfer_mbox) > 1) {
        lv_obj_t * bar = lv_obj_get_child(bt_transfer_mbox, NULL);
        lv_obj_del(bar);
    }

    uint16_t txtId = 0;
    if(PROCESS_RECV_FILE == process) {
        txtId = success == 1 ? WATCH_TEXT_ID_RECEIVE_FINISHED : WATCH_TEXT_ID_RECEIVE_FAILED;
    } else {
        txtId = success == 1 ? WATCH_TEXT_ID_SEND_SUCCESS : WATCH_TEXT_ID_SEND_FAILED;
    }
    lv_msgbox_set_text(bt_transfer_mbox, (char *)lv_lang_get_text(txtId));

    static const char * finish_txt[2];
    finish_txt[0] = (char *)lv_lang_get_text(WATCH_TEXT_ID_OK);
    finish_txt[1] = "";
    lv_msgbox_add_btns(bt_transfer_mbox, finish_txt);
    lv_obj_set_event_cb(lv_msgbox_get_btnmatrix(bt_transfer_mbox), bluetooth_transfer_file_finish_action);
    lv_obj_realign(bt_transfer_mbox);
}

static char * bluetooth_adjust_file_name(char * name)
{
    char * new_name = NULL;
    char temp_dot[] = "....";

    if(BT_OBEX_FILE_NAME_MAX_DISPLAY >= strlen(name)) {
        new_name = (char *)lv_mem_alloc(strlen(name) + 1);
        memset(new_name, 0, strlen(name) + 1);
        strncpy(new_name, name, strlen(name));
    } else {
        new_name = (char *)lv_mem_alloc(BT_OBEX_FILE_NAME_MAX_DISPLAY + 1);
        memset(new_name, 0, BT_OBEX_FILE_NAME_MAX_DISPLAY + 1);
        uint8_t ext_len = strlen(lv_fs_get_ext(name));
        strncpy(new_name, name, BT_OBEX_FILE_NAME_MAX_DISPLAY - strlen(temp_dot) - ext_len);
        strncpy(new_name + (BT_OBEX_FILE_NAME_MAX_DISPLAY - strlen(temp_dot) - ext_len), temp_dot, strlen(temp_dot));
        strncpy(new_name + (BT_OBEX_FILE_NAME_MAX_DISPLAY - ext_len), name + (strlen(name) - ext_len), ext_len);
        printf("%s: new_name = %s\n", __FUNCTION__, new_name);
    }

    return new_name;
}

static void bluetooth_paired_confirm_action(lv_obj_t * btnm, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    char * txt = (char *)lv_btnmatrix_get_active_btn_text(btnm);
    lv_obj_t * mbox = lv_obj_get_parent(btnm);
    char * addr = lv_watch_get_free_ptr(mbox);
    struct bt_addr dev_addr;
    memcpy(dev_addr.bytes, addr, 6);
    lv_mem_free(addr);
    if(strcmp(txt, (char *)lv_lang_get_text(WATCH_TEXT_ID_OK)) == 0) {
        bt_accept_bonding_device(dev_addr, 1);
    } else {
        bt_accept_bonding_device(dev_addr, 0);
    }
    lv_obj_del(lv_obj_get_parent(mbox));
    bt_transfer_mbox = NULL;
}

void bluetooth_paired_confirm(char * dev_name, char * addr)
{
    watch_wakeup_lcd(true);

    if(bt_transfer_mbox != NULL) {
        lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(bt_transfer_mbox);
        if(ext->btnm && lv_obj_get_event_cb(ext->btnm) == bluetooth_transfer_file_finish_action) {
            printf("%s:bt transfer finished\n", __FUNCTION__);
            bluetooth_transfer_file_finish_action(ext->btnm, LV_EVENT_CLICKED);
        }
    }
    lv_obj_t * parent;
    lv_obj_t * phone_obj = lv_watch_get_activity_obj(ACT_ID_PHONE);
    lv_obj_t * voipphone_obj = lv_watch_get_activity_obj(ACT_ID_VOIPPHONE);
    lv_obj_t * slider_obj = lv_watch_get_activity_obj(ACT_ID_SLIDER);

    if(phone_obj)
        parent = _lv_ll_get_next(&(lv_scr_act())->child_ll, phone_obj);
    else if(voipphone_obj)
        parent = _lv_ll_get_next(&(lv_scr_act())->child_ll, voipphone_obj);
    else if(slider_obj)
        parent = _lv_ll_get_next(&(lv_scr_act())->child_ll, slider_obj);
    else
        parent = lv_watch_get_top_activity_obj();

    printf("bt+++ %s:name: %s\n", __FUNCTION__, dev_name);
    lv_obj_t * content = lv_cont_create(parent, NULL);
    lv_obj_set_size(content, LV_HOR_RES, LV_VER_RES);
    lv_obj_add_style(content, LV_CONT_PART_MAIN, &lv_watch_style_transp);
    bt_transfer_mbox = lv_msgbox_create(content, NULL);
    lv_obj_set_top(bt_transfer_mbox, true);
    lv_obj_set_width(bt_transfer_mbox, LV_HOR_RES * 4 / 5);
    char str[MAX_BT_NAME + 20];
    snprintf(str, MAX_BT_NAME + 20, "%s\n%s", dev_name, (char *)lv_lang_get_text(WATCH_TEXT_ID_PAIRED_CONFIRM));
    lv_msgbox_set_text(bt_transfer_mbox, str);
    char *addr_ptr = lv_mem_alloc(6);
    memcpy(addr_ptr, addr, 6);
    lv_watch_set_free_ptr(bt_transfer_mbox, addr_ptr);

    static const char * txt[3];
    txt[0] = (char *)lv_lang_get_text(WATCH_TEXT_ID_OK);
    txt[1] = (char *)lv_lang_get_text(WATCH_TEXT_ID_CANCEL);
    txt[2] = "";
    lv_msgbox_add_btns(bt_transfer_mbox, txt);
    lv_obj_t * btnm = lv_msgbox_get_btnmatrix(bt_transfer_mbox);
    lv_obj_set_event_cb(btnm, bluetooth_paired_confirm_action);
    lv_obj_align(bt_transfer_mbox, NULL, LV_ALIGN_CENTER, 0, 0);
    lv_watch_set_free_num(bt_transfer_mbox, PROCESS_PAIRED_CONFIRM);
}

void bluetooth_receive_file_confirm(uint8_t is_finish)
{
    if(!watch_get_lcd_status()) watch_set_lcd_status(true);
    watch_set_suspend_enable(false, ACT_ID_BLUETOOTH, 0);

    bt_file_receive_context * file_cont = bt_get_receive_file_info();
    if(file_cont == NULL) return;

    if(bt_transfer_mbox != NULL) {
        if(lv_obj_get_user_data(bt_transfer_mbox).user_num == PROCESS_RECV_FILE || lv_obj_get_user_data(bt_transfer_mbox).user_num == PROCESS_SEND_FILE) {
            lv_obj_del(lv_obj_get_parent(bt_transfer_mbox));
        }
        bt_transfer_mbox = NULL;
    }
    lv_obj_t * parent;
    lv_obj_t * phone_obj = lv_watch_get_activity_obj(ACT_ID_PHONE);
    lv_obj_t * voipphone_obj = lv_watch_get_activity_obj(ACT_ID_VOIPPHONE);
    lv_obj_t * slider_obj = lv_watch_get_activity_obj(ACT_ID_SLIDER);

    if(phone_obj)
        parent = _lv_ll_get_next(&(lv_scr_act())->child_ll, phone_obj);
    else if(voipphone_obj)
        parent = _lv_ll_get_next(&(lv_scr_act())->child_ll, voipphone_obj);
    else if(slider_obj)
        parent = _lv_ll_get_next(&(lv_scr_act())->child_ll, slider_obj);
    else
        parent = lv_watch_get_top_activity_obj();

    lv_obj_t * content = lv_cont_create(parent, NULL);
    lv_obj_set_size(content, LV_HOR_RES, LV_VER_RES);
    lv_obj_add_style(content, LV_CONT_PART_MAIN, &lv_watch_style_transp);
    bt_transfer_mbox = lv_msgbox_create(content, NULL);
    lv_obj_set_top(bt_transfer_mbox, true);
    lv_obj_set_width(bt_transfer_mbox, LV_HOR_RES * 4 / 5);
    char str[MAX_BT_OBEX_FILE_NAME + 20];
    printf("bt file confirm name= %s\n", file_cont->file_name);
    char * display_name = bluetooth_adjust_file_name(file_cont->file_name);
    snprintf(str, MAX_BT_OBEX_FILE_NAME + 20, "%s\n%s?", (char *)lv_lang_get_text(WATCH_TEXT_ID_RECEIVE_FILE), display_name);
    lv_msgbox_set_text(bt_transfer_mbox, str);
    if(NULL != display_name) {
        lv_mem_free(display_name);
    }

    static const char * txt[3];
    txt[0] = (char *)lv_lang_get_text(WATCH_TEXT_ID_OK);
    txt[1] = (char *)lv_lang_get_text(WATCH_TEXT_ID_CANCEL);
    txt[2] = "";
    lv_msgbox_add_btns(bt_transfer_mbox, txt);
    lv_obj_t * btnm = lv_msgbox_get_btnmatrix(bt_transfer_mbox);
    lv_obj_set_event_cb(btnm, bluetooth_receive_file_confirm_action);
    lv_watch_set_free_num(btnm, is_finish);
    lv_obj_align(bt_transfer_mbox, NULL, LV_ALIGN_CENTER, 0, 0);
    lv_watch_set_free_num(bt_transfer_mbox, PROCESS_RECV_FILE);
}

void bluetooth_send_file_mbox(char * name)
{
    if(!watch_get_lcd_status()) watch_set_lcd_status(true);
    watch_set_suspend_enable(false, ACT_ID_BLUETOOTH, 0);

    if(bt_transfer_mbox != NULL) {
        if(lv_obj_get_user_data(bt_transfer_mbox).user_num == PROCESS_RECV_FILE || lv_obj_get_user_data(bt_transfer_mbox).user_num == PROCESS_SEND_FILE) {
            lv_obj_del(lv_obj_get_parent(bt_transfer_mbox));
        }
        bt_transfer_mbox = NULL;
    }
    lv_obj_t * content = lv_cont_create(lv_watch_get_top_activity_obj(), NULL);
    lv_obj_set_size(content, LV_HOR_RES, LV_VER_RES);
    lv_obj_add_style(content, LV_CONT_PART_MAIN, &lv_watch_style_transp);
    bt_transfer_mbox = lv_msgbox_create(content, NULL);
    lv_obj_set_top(bt_transfer_mbox, true);
    lv_obj_set_width(bt_transfer_mbox, LV_HOR_RES * 4 / 5);
    char str[MAX_BT_OBEX_FILE_NAME + 20];
    char * display_name = NULL;
    if(strcmp(name, PHOTO_SHARE_TMEP_PATH) == 0) {
        snprintf(str, MAX_BT_OBEX_FILE_NAME + 20, "%s\n%s",
                 (char *)lv_lang_get_text(WATCH_TEXT_ID_READY_TO_SEND_FILE), (char *)lv_lang_get_text(WATCH_TEXT_ID_TEMP_PHOTO));
        lv_watch_set_free_ptr(bt_transfer_mbox, (void *)PHOTO_SHARE_TMEP_PATH);
    } else {
        display_name = bluetooth_adjust_file_name(name);
        snprintf(str, MAX_BT_OBEX_FILE_NAME + 20, "%s\n%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_READY_TO_SEND_FILE), display_name);
    }
    lv_msgbox_set_text(bt_transfer_mbox, str);
    if(NULL != display_name) {
        lv_mem_free(display_name);
    }

    static const char * txt[2];
    txt[0] = (char *)lv_lang_get_text(WATCH_TEXT_ID_CANCEL);
    txt[1] = "";
    lv_msgbox_add_btns(bt_transfer_mbox, txt);
    lv_obj_set_event_cb(lv_msgbox_get_btnmatrix(bt_transfer_mbox), bluetooth_sendfile_cancel_action);
    lv_obj_align(bt_transfer_mbox, NULL, LV_ALIGN_CENTER, 0, 0);
    lv_watch_set_free_num(bt_transfer_mbox, PROCESS_SEND_FILE);
}

void bluetooth_send_file_start(void)
{
    if(NULL == bt_transfer_mbox) return;
    if(strcmp((char *)lv_lang_get_text(WATCH_TEXT_ID_SEND_FAILED), lv_msgbox_get_text(bt_transfer_mbox)) == 0) return;
    lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(bt_transfer_mbox);
    lv_obj_del(ext->btnm);
    ext->btnm = NULL;
    lv_msgbox_set_text(bt_transfer_mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_SENDING_FILE));

    lv_obj_t * bar = lv_bar_create(bt_transfer_mbox, NULL);
    lv_obj_set_style_local_bg_color(bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x00, 0x99, 0xFF));
    lv_obj_set_style_local_bg_grad_color(bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x15, 0x68, 0xD2));
    lv_obj_set_size(bar, lv_obj_get_width(bt_transfer_mbox) - 8, 20);
    lv_obj_align(bar, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5);
    lv_bar_set_value(bar, 0, LV_ANIM_OFF);
    lv_obj_realign(bt_transfer_mbox);
}

bool bluetooth_transfer_file_warning(void)
{
    if(bt_transfer_mbox == NULL) {
        printf("bt no transfer mbox, close normally\n");
        return false;
    }
    if(lv_obj_get_user_data(bt_transfer_mbox).user_num == PROCESS_PAIRED_CONFIRM) {
        char * addr = lv_watch_get_free_ptr(bt_transfer_mbox);
        struct bt_addr dev_addr;
        memcpy(dev_addr.bytes, addr, 6);
        lv_mem_free(addr);
        bt_accept_bonding_device(dev_addr, 0);
        lv_obj_del(lv_obj_get_parent(bt_transfer_mbox));
        bt_transfer_mbox = NULL;
        return false;
    }
    if(lv_obj_get_user_data(bt_transfer_mbox).user_num != PROCESS_RECV_FILE && lv_obj_get_user_data(bt_transfer_mbox).user_num != PROCESS_SEND_FILE) {
        printf("bt invalid transfer mbox address\n");
        return false;
    }
    lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(bt_transfer_mbox);
    if(ext->btnm && lv_obj_get_event_cb(ext->btnm) == bluetooth_transfer_file_finish_action) {
        printf("bt transfer finished, mbox can be destroy\n");
        bluetooth_transfer_file_finish_action(bt_transfer_mbox, LV_EVENT_CLICKED);
        return false;
    }
    printf("bt transfer is processing, can't close!!");
    lv_obj_t * warn_box = lv_msgbox_create(lv_watch_get_top_activity_obj(), NULL);
    lv_obj_set_width(warn_box, LV_HOR_RES * 4 / 5);
    lv_msgbox_set_text(warn_box, (char *)lv_lang_get_text(WATCH_TEXT_ID_TRANS_FLIE_WARNING));
    lv_obj_realign(warn_box);
    lv_msgbox_set_anim_time(warn_box, 0);
    lv_msgbox_start_auto_close(warn_box, 2000);
    return true;
}

/**********************
 *   STATIC FUNCTIONS
 **********************/
static lv_obj_t * bluetooth_create(lv_obj_t * activity_obj)
{
    if(NULL == activity_obj) {
        lv_watch_activity_ext_t activity_ext;
        memset(&activity_ext, 0, sizeof(lv_watch_activity_ext_t));
        activity_ext.actId = ACT_ID_BLUETOOTH;
        activity_ext.create = bluetooth_create;
        activity_ext.prepare_destory = bluetooth_prepare_destory;
        activity_obj = lv_watch_creat_activity_obj(&activity_ext);
        LV_ASSERT_MEM(activity_obj);
        if(NULL == activity_obj) {
            return NULL;
        }
    }

    bt_setting_present = true;
    lv_obj_t * obj = lv_watch_obj_create(activity_obj);
    LV_ASSERT_MEM(obj);
    if(NULL == obj) {
        return NULL;
    }

    lv_bluetooth_obj_ext_t * ext = lv_obj_allocate_ext_attr(obj, sizeof(lv_bluetooth_obj_ext_t));
    ext->paired_label = NULL;
    ext->available_label = NULL;
    ext->refresh_btn = NULL;
    ext->dev_list = NULL;
    ext->title_label = NULL;
    ext->opening_label = NULL;
    ext->sw = NULL;
    ext->mbox = NULL;
    ext->preload = NULL;

    bluetooth_btn_style_init(ext);
    // sw_knob_off.body.main_color = LV_COLOR_MAKE(0xC0, 0xC0, 0xC0);

    lv_obj_t * title_label = lv_label_create(obj, NULL);
    lv_obj_add_style(title_label, LV_LABEL_PART_MAIN, &lv_watch_font20_gray);
    lv_label_set_align(title_label, LV_LABEL_ALIGN_CENTER);
    lv_obj_set_click(title_label, false);
    lv_label_set_text_id(title_label, WATCH_TEXT_ID_BLUETOOTH);
    lv_obj_align(title_label, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);

    lv_obj_t * content1 = lv_cont_create(obj, NULL);
    lv_obj_set_size(content1, LV_HOR_RES, LV_VER_RES / 8);
    lv_obj_add_style(content1, LV_CONT_PART_MAIN, &lv_watch_cont_opa1);
    lv_obj_set_style_local_radius(content1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
    lv_obj_set_style_local_pad_left(content1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 6);
    lv_obj_set_style_local_pad_right(content1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 6);
    lv_obj_set_click(content1, false);
    lv_cont_set_layout(content1, LV_LAYOUT_ROW_MID);
    lv_obj_align(content1, title_label, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
    lv_obj_t * sw_label = lv_label_create(content1, NULL);
    lv_label_set_text_id(sw_label, WATCH_TEXT_ID_BLUETOOTH);
    lv_obj_add_style(sw_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_t * sw = lv_switch_create(content1, NULL);
    lv_obj_set_size(sw, LV_HOR_RES / 5, lv_obj_get_height(sw_label));
    old_sw_signal = lv_obj_get_signal_cb(sw);
    lv_obj_set_signal_cb(sw, bluetooth_switch_signal);
    lv_obj_set_style_local_bg_color(sw, LV_SWITCH_PART_BG, LV_STATE_DEFAULT, LV_COLOR_SILVER);
    lv_obj_set_style_local_bg_color(sw, LV_SWITCH_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_SILVER);
    lv_obj_set_style_local_bg_color(sw, LV_SWITCH_PART_BG, LV_STATE_CHECKED, LV_COLOR_MAKE(0x15, 0x68, 0xD2));
    lv_obj_set_style_local_bg_color(sw, LV_SWITCH_PART_INDIC, LV_STATE_CHECKED, LV_COLOR_MAKE(0x15, 0x68, 0xD2));
    ext->sw = sw;
    lv_obj_set_style_local_pad_inner(content1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT,
                                     lv_obj_get_width(content1) - lv_obj_get_width(sw_label) - lv_obj_get_width(sw) - 12);

    lv_obj_t * content2 = lv_cont_create(obj, content1);
    lv_obj_align(content2, content1, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
    lv_obj_t * name_label1 = lv_label_create(content2, sw_label);
    lv_label_set_text_id(name_label1, WATCH_TEXT_ID_DEVICE_NAME);

    lv_obj_t * name_label2 = lv_label_create(content2, title_label);
    char name[9];
    bt_get_device_name(name);
    lv_label_set_text(name_label2, name);
    lv_obj_set_style_local_pad_inner(content2, LV_CONT_PART_MAIN, LV_STATE_DEFAULT,
                                     lv_obj_get_width(content2) - lv_obj_get_width(name_label1) - lv_obj_get_width(name_label2) - 12);

    ext->opening_label = lv_label_create(obj, title_label);
    lv_label_set_text_id(ext->opening_label, WATCH_TEXT_ID_OPENING);
    lv_obj_align(ext->opening_label, content2, LV_ALIGN_OUT_BOTTOM_MID, 0, 30);
    lv_obj_set_hidden(ext->opening_label, true);

    lv_obj_t * p_dev_btn = lv_btn_create(obj, NULL);
    lv_obj_set_size(p_dev_btn, LV_HOR_RES, LV_VER_RES / 8);
    lv_obj_align(p_dev_btn, content2, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
    lv_obj_add_style(p_dev_btn, LV_BTN_PART_MAIN, &(ext->btn_rel));
    lv_obj_set_event_cb(p_dev_btn, bluetooth_dev_btn_action);
    lv_btn_set_layout(p_dev_btn, LV_LAYOUT_ROW_MID);
    lv_obj_t * p_dev_label = lv_label_create(p_dev_btn, NULL);
    lv_obj_add_style(p_dev_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_label_set_text_id(p_dev_label, WATCH_TEXT_ID_PAIRED_DEV);
    lv_obj_t * s_label = lv_label_create(p_dev_btn, p_dev_label);
    if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL)
        lv_label_set_text(s_label, LV_SYMBOL_LEFT);
    else
        lv_label_set_text(s_label, LV_SYMBOL_RIGHT);
    lv_obj_set_style_local_text_font(s_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_THEME_WATCH_NIGHT_SYMBOL_NORMAL);
    lv_watch_set_free_num(p_dev_btn, WATCH_TEXT_ID_PAIRED_DEV);
    lv_watch_obj_add_element(p_dev_btn);
    lv_obj_set_style_local_pad_left(p_dev_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 10);
    lv_obj_set_style_local_pad_right(p_dev_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 10);
    lv_obj_set_style_local_pad_inner(p_dev_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT,
                                     lv_obj_get_width(p_dev_btn) - lv_obj_get_width(p_dev_label) - lv_obj_get_width(s_label) - 20);


    lv_obj_t * a_dev_btn = lv_btn_create(obj, p_dev_btn);
    lv_obj_align(a_dev_btn, p_dev_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
    lv_obj_set_event_cb(a_dev_btn, bluetooth_dev_btn_action);
    lv_obj_t * a_dev_label = lv_label_create(a_dev_btn, p_dev_label);
    lv_label_set_text_id(a_dev_label, WATCH_TEXT_ID_AVAILABLE_DEV);
    s_label = lv_label_create(a_dev_btn, s_label);
    lv_watch_set_free_num(a_dev_btn, WATCH_TEXT_ID_AVAILABLE_DEV);
    lv_watch_obj_add_element(a_dev_btn);
    lv_obj_set_style_local_pad_inner(a_dev_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT,
                                     lv_obj_get_width(a_dev_btn) - lv_obj_get_width(a_dev_label) - lv_obj_get_width(s_label) - 20);

    lv_obj_t * r_btn = lv_btn_create(obj, p_dev_btn);
    lv_obj_add_style(r_btn, LV_BTN_PART_MAIN, &ext->btn_rel);
    lv_obj_align(r_btn, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5);
    lv_obj_set_event_cb(r_btn, bluetooth_refresh_btn_action);
    lv_obj_t * r_label = lv_label_create(r_btn, p_dev_label);
    lv_label_set_text_id(r_label, WATCH_TEXT_ID_REFRESH);
    lv_obj_t * r_symbol  = lv_label_create(r_btn, s_label);
    lv_label_set_text(r_symbol, LV_SYMBOL_REFRESH);
    lv_watch_obj_add_element(r_btn);
    lv_obj_set_style_local_pad_inner(r_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT,
                                     lv_obj_get_width(r_btn) - lv_obj_get_width(r_label) - lv_obj_get_width(r_symbol) - 20);

    ext->paired_label = p_dev_label;
    ext->available_label = a_dev_label;
    ext->refresh_btn = r_btn;
    bluetooth_show_object(false);
    bluetooth_open_state_init();
    bluetooth_update_paired_label_show();
    return obj;
}

static void bluetooth_open_state_init(void)
{
    nv_watch_bluetooth_t * nvm = bluetooth_read_nvm();
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    printf("bt nvm on_off = %d bt_opened = %d\n", nvm->on_off, bt_get_state());
    if(nvm->on_off == 1) {
        bt_adp_task_create();
        bt_list_init();
        if(bt_get_state()) {
            bluetooth_show_object(true);
        } else {
            lv_obj_set_hidden(ext->opening_label, false);
            bt_open_device();
        }
    } else {
        if(bt_get_state()) {
            bt_adp_task_create();
            bt_list_init();
            bluetooth_show_object(true);
        }
    }
    lv_mem_free(nvm);
}

static void bluetooth_dev_btn_action(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    lv_event_cb_t action;
    bluetooth_cancel_inquiry();
    uint16_t txtId = lv_obj_get_user_data(btn).user_num;
    if(WATCH_TEXT_ID_PAIRED_DEV == txtId) {
        if(bt_get_paired_dev_cnt() == 0) return;
        action = bluetooth_paired_list_btn_action;
    } else {
        if(bt_get_scan_dev_cnt() == 0) return;
        action = bluetooth_availabel_list_btn_action;
    }
    bluetooth_dev_list_create(lv_obj_get_parent(btn), txtId, action);
}

static void bluetooth_back_img_event_cb(lv_obj_t * obj, lv_event_t e)
{
    if(LV_EVENT_CLICKED == e) {
        uint8_t num = lv_obj_get_user_data(obj).user_num;
        lv_obj_del(lv_obj_get_parent(obj));
        if(num == 1) {
            bluetooth_update_scan_label_show();
            bluetooth_update_paired_label_show();
            lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
            ext->dev_list = NULL;
            ext->title_label = NULL;
            ext->mbox = NULL;
        }
    }
}
/*
static lv_res_t bluetooth_mbox_action(lv_obj_t * btn, const char * txt)
{
    struct bt_addr addr;
    char str[64];
    lv_obj_t * mbox = lv_mbox_get_from_btn(btn);
    uint8_t process = lv_obj_get_free_num(mbox);
    if(process == 0) {//0--pairing 1--connecting
        struct bt_event_inquiry * info = (struct bt_event_inquiry *)lv_obj_get_free_ptr(mbox);
        memcpy(addr.bytes, info->addr, 6);
        snprintf(str, 64, "%s\n%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_PAIRING), info->name);
    } else {
        bt_dev_info_t * info = (bt_dev_info_t *)lv_obj_get_free_ptr(mbox);
        memcpy(addr.bytes, info->addr, 6);
        snprintf(str, 64, "%s\n%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_CONNECTING), info->name);
    }
    if(strcmp(txt, (char *)lv_lang_get_text(WATCH_TEXT_ID_OK)) == 0) {
        if(process == 0) bt_accept_bonding_device(addr, 1);
        else bt_accept_connect_device(addr, 1);

        lv_mbox_set_text(mbox, str);
        lv_mbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
        lv_obj_del(ext->btnm);
        ext->btnm = NULL;
        lv_obj_realign(mbox);
    } else {
        if(process == 0) bt_accept_bonding_device(addr, 0);
        else  bt_accept_connect_device(addr, 0);

        lv_obj_del(mbox);
        bluetooth_get_ext()->mbox = NULL;
    }
    return LV_RES_OK;
}
*/

static void bluetooth_receive_abort_action(lv_obj_t * btnm, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    lv_obj_del(lv_obj_get_parent(lv_obj_get_parent(btnm)));
}

static void bluetooth_sendfile_cancel_action(lv_obj_t * btnm, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    if(0 == bt_file_send_cancel()) {
        bluetooth_transfer_file_finish(PROCESS_SEND_FILE, 0);
    }
}

static void bluetooth_receive_file_confirm_action(lv_obj_t * btnm, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    char * txt = (char *)lv_btnmatrix_get_active_btn_text(btnm);
    uint8_t is_finish = lv_watch_get_free_num(btnm);
    if(strcmp(txt, (char *)lv_lang_get_text(WATCH_TEXT_ID_OK)) == 0) {
        lv_msgbox_set_text(bt_transfer_mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_RECEIVING_FILE));
        lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(bt_transfer_mbox);
        lv_obj_del(ext->btnm);
        ext->btnm = NULL;

        lv_obj_t * bar = lv_bar_create(bt_transfer_mbox, NULL);
        lv_obj_set_style_local_bg_color(bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x00, 0x99, 0xFF));
        lv_obj_set_style_local_bg_grad_color(bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x15, 0x68, 0xD2));
        lv_obj_set_size(bar, lv_obj_get_width(bt_transfer_mbox) - 8, 20);
        lv_obj_align(bar, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5);
        lv_bar_set_value(bar, 0, LV_ANIM_OFF);
        lv_obj_realign(bt_transfer_mbox);
        bt_file_receive_continue();

        if(1 == is_finish) {
            bluetooth_receive_file_process_update_and_finish();
        }

    } else {
        if(1 == is_finish) {
            printf("%s: finish message has been received\n", __FUNCTION__);
            bt_clear_received_file();
        }
        bt_file_receive_cancel();
        lv_obj_del(lv_obj_get_parent(bt_transfer_mbox));
        bt_transfer_mbox = NULL;
        watch_set_suspend_enable(true, ACT_ID_BLUETOOTH, 0);
    }
}

static void bluetooth_transfer_file_finish_action(lv_obj_t * btnm, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    album_send_file_finish_action();
    if(lv_obj_get_user_data(bt_transfer_mbox).user_num == PROCESS_SEND_FILE
       && (strcmp((char *)lv_obj_get_user_data(bt_transfer_mbox).user_data, PHOTO_SHARE_TMEP_PATH) == 0)) {
        printf("delete temp share photo\n");
        lv_fs_remove(PHOTO_SHARE_TMEP_PATH);
    }
    lv_obj_del(lv_obj_get_parent(bt_transfer_mbox));
    bt_transfer_mbox = NULL;
#if USE_LV_WATCH_SD_AUTO_MOUNT != 0
    printf("%s: bluetooth release completely, release other app\n", __FUNCTION__);
    if(setting_get_release_capture_app_proc()) {
        setting_set_release_capture_app_proc(false);
        setting_sd_mount_common_destory_capture_app();
    }
#endif
}

static void bluetooth_update_paired_label_show(void)
{
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    if(NULL == ext) return;
    char str[20];
    if(bt_get_paired_dev_cnt() == 0)
        lv_label_set_text_id(ext->paired_label, WATCH_TEXT_ID_PAIRED_DEV);
    else {
        memset(str, 0, 20);
        snprintf(str, 20, "%s(%d)", (char *)lv_lang_get_text(WATCH_TEXT_ID_PAIRED_DEV), bt_get_paired_dev_cnt());
        lv_label_set_text(ext->paired_label, str);
    }
}

static void bluetooth_create_scan_dev_list(lv_obj_t * list)
{
    uint8_t i = 0;
    lv_obj_t * btn;
    char str[MAX_BT_NAME];
    struct bt_event_inquiry * scan_list = bt_get_scan_list();
    for(i = 0; i < bt_get_scan_dev_cnt(); i++) {
        memset(str, 0, MAX_BT_NAME);
        if(scan_list[i].name[0] == NULL) {
            snprintf(str, MAX_BT_NAME, "%2x:%2x:%2x:%2x:%2x:%2x", scan_list[i].addr[0], scan_list[i].addr[1], scan_list[i].addr[2],
                     scan_list[i].addr[3], scan_list[i].addr[4], scan_list[i].addr[5]);
        } else {
            snprintf(str, MAX_BT_NAME, "%s", scan_list[i].name);
        }
        btn = bluetooth_dev_list_add(list, PROFILE_STATE_MAX, str, bluetooth_availabel_list_btn_action, (scan_list[i].cod & COD_TYPE_HEADSET));
        lv_watch_set_free_num(btn, i);
    }
}

static void bluetooth_create_paired_dev_list(lv_obj_t * list)
{
    uint8_t i = 0;
    lv_obj_t * btn;
    char name_str[MAX_BT_NAME];
    bt_paired_dev_t * paired_list = bt_get_paired_list();
    for(i = 0; i < bt_get_paired_dev_cnt(); i++) {
        memset(name_str, 0, MAX_BT_NAME);
        if(paired_list[i].name[0] == NULL) {
            snprintf(name_str, MAX_BT_NAME, "%2x:%2x:%2x:%2x:%2x:%2x", paired_list[i].addr[0], paired_list[i].addr[1], paired_list[i].addr[2],
                     paired_list[i].addr[3], paired_list[i].addr[4], paired_list[i].addr[5]);
        } else {
            snprintf(name_str, MAX_BT_NAME, "%s", paired_list[i].name);
            btn =  bluetooth_dev_list_add(list,
                                          paired_list[i].profile_status[PROFILE_CONNECTION], name_str, bluetooth_paired_list_btn_action,
                                          (paired_list[i].cod & COD_TYPE_HEADSET));
            lv_watch_set_free_ptr(btn, &paired_list[i]);
        }
        printf("bt pairedlist create name=%s\n", name_str);
    }
    for(i = 0; i < bt_get_paired_dev_cnt(); i++) {
        if(paired_list[i].profile_status[PROFILE_CONNECTION] == PROFILE_STATE_CONNECTING) {
            bluetooth_processing_mbox_create((char *)paired_list[i].name, PROCESS_CONNECT);
            break;
        }
    }
}

static lv_obj_t * bluetooth_dev_list_create(lv_obj_t * par, uint16_t txtId, lv_event_cb_t rel_action)
{
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    lv_obj_t * bg = lv_img_create(par, NULL);
    lv_img_set_src(bg, watch_get_bg());
    lv_obj_t * back_img = lv_img_create(bg, NULL);
    lv_img_set_src(back_img, ICON_ALBUM_BACK);
    lv_obj_set_click(back_img, true);
    lv_watch_set_free_num(back_img, 1);
    lv_obj_set_event_cb(back_img, bluetooth_back_img_event_cb);
    lv_obj_t * label = lv_label_create(bg, NULL);
    lv_label_set_text_id(label, txtId);
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20_gray);
    if(lv_obj_get_base_dir(par) == LV_BIDI_DIR_RTL) {
        lv_obj_align(back_img, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
        lv_img_set_angle(back_img, 1800);
        lv_obj_align(label, back_img, LV_ALIGN_OUT_LEFT_MID, -(LV_HOR_RES / 2  - lv_obj_get_width(back_img) - lv_obj_get_width(label) / 2), 0);
    } else {
        lv_obj_align(back_img, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
        lv_obj_align(label, back_img, LV_ALIGN_OUT_RIGHT_MID, LV_HOR_RES / 2 - lv_obj_get_width(back_img) - lv_obj_get_width(label) / 2, 0);
    }
    ext->title_label = label;
    lv_obj_t * list = lv_list_create(bg, NULL);
    lv_obj_set_size(list, LV_HOR_RES, LV_VER_RES - 40);
    lv_obj_align(list, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
    lv_page_set_scrollbar_mode(list, LV_SCROLLBAR_MODE_OFF);
    lv_obj_add_style(list, LV_LIST_PART_BG, &lv_watch_style_transp);
    lv_obj_set_style_local_pad_inner(list, LV_LIST_PART_BG, LV_STATE_DEFAULT, 0);
    lv_obj_set_style_local_pad_left(list, LV_LIST_PART_BG, LV_STATE_DEFAULT, 5);
    lv_obj_set_style_local_pad_right(list, LV_LIST_PART_BG, LV_STATE_DEFAULT, 5);
    lv_obj_add_style(list, LV_LIST_PART_SCROLLABLE, &lv_watch_style_transp);
    lv_obj_set_style_local_pad_inner(list, LV_LIST_PART_SCROLLABLE, LV_STATE_DEFAULT, 0);
    lv_obj_set_style_local_pad_left(list, LV_LIST_PART_SCROLLABLE, LV_STATE_DEFAULT, 5);
    lv_obj_set_style_local_pad_right(list, LV_LIST_PART_SCROLLABLE, LV_STATE_DEFAULT, 5);
    ext->dev_list = list;
    if(txtId == WATCH_TEXT_ID_PAIRED_DEV) bluetooth_create_paired_dev_list(list);
    else bluetooth_create_scan_dev_list(list);

    return list;
}

static void bluetooth_cancel_inquiry(void)
{
    bt_inquiry_device_cancel();
    watch_set_suspend_enable(true, ACT_ID_BLUETOOTH, 0);
}

static void bluetooth_prepare_destory(lv_obj_t * activity_obj)
{
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    lv_style_reset(&(ext->btn_rel));

    bluetooth_cancel_inquiry();
    lv_watch_png_cache_all_free();
    bt_setting_present = false;
}

static void bluetooth_btn_style_init(lv_bluetooth_obj_ext_t * ext)
{
    lv_style_init(&(ext->btn_rel));
    lv_style_copy(&(ext->btn_rel), &lv_watch_style_transp);
    lv_style_set_radius(&(ext->btn_rel), LV_STATE_DEFAULT, 0);
    lv_style_set_border_width(&(ext->btn_rel), LV_STATE_DEFAULT, 1);
    lv_style_set_border_side(&(ext->btn_rel), LV_STATE_DEFAULT, LV_BORDER_SIDE_BOTTOM);
    lv_style_set_border_color(&(ext->btn_rel), LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_radius(&(ext->btn_rel), LV_STATE_PRESSED, 5);
    lv_style_set_border_width(&(ext->btn_rel), LV_STATE_PRESSED, 1);
    lv_style_set_border_side(&(ext->btn_rel), LV_STATE_PRESSED, LV_BORDER_SIDE_BOTTOM);
    lv_style_set_border_color(&(ext->btn_rel), LV_STATE_PRESSED, LV_COLOR_WHITE);
    lv_style_set_bg_opa(&(ext->btn_rel), LV_STATE_PRESSED, LV_OPA_30);
}

static lv_res_t bluetooth_switch_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
{
    if(sign == LV_SIGNAL_RELEASED) {
        lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
        if(lv_obj_get_hidden(ext->opening_label) == false &&
           (lv_watch_get_free_num(ext->opening_label) == WATCH_TEXT_ID_OPENING || lv_watch_get_free_num(ext->opening_label) == WATCH_TEXT_ID_CLOSING)) {
            printf("%s: processing....\n", __FUNCTION__);
            return LV_RES_OK;
        }
        if(lv_switch_get_state(sw) == 0) {
            bt_adp_task_create();
            bt_list_init();
            if(lv_obj_get_hidden(ext->opening_label))
                lv_obj_set_hidden(ext->opening_label, false);
            lv_label_set_text_id(ext->opening_label, WATCH_TEXT_ID_OPENING);
            lv_refr_now(NULL);
            int32_t ret = bt_open_device();
            if(ret != 0) {
                lv_label_set_text_id(ext->opening_label, WATCH_TEXT_ID_OPEN_FAILED);
                lv_obj_realign(ext->opening_label);
                bt_list_destroy();
                bt_adp_task_destroy();
            }
        } else {
            bt_close_device();
            bluetooth_clean_scan_list();
            bluetooth_show_object(false);
            lv_label_set_text_id(ext->opening_label, WATCH_TEXT_ID_CLOSING);
            lv_obj_set_hidden(ext->opening_label, false);
            watch_set_suspend_enable(true, ACT_ID_BLUETOOTH, 0);
        }
        return LV_RES_OK;
    }
    return old_sw_signal(sw, sign, param);
}

static void bluetooth_process_btn_action(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    uint16_t txtid = lv_obj_get_user_data(lv_obj_get_child(btn, NULL)).user_num;
    bt_paired_dev_t * dev = (bt_paired_dev_t *) lv_obj_get_user_data(btn).user_data;
    struct bt_addr addr;
    int32_t ret = 0;
    memcpy(addr.bytes, dev->addr, 6);
    lv_obj_del(lv_obj_get_parent(btn));
    if(WATCH_TEXT_ID_UNPAIRED == txtid) {
        bluetooth_processing_mbox_create((char *)dev->name, PROCESS_UNPAIR);
        ret = bt_remove_device(addr, dev->cod);
    } else if(WATCH_TEXT_ID_CONNECT == txtid) {
        if(bt_get_headset_connect() || bt_transfer_mbox != NULL) {
            lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
            bluetooth_tip_mbox_create(lv_obj_get_parent(ext->dev_list));
            return;
        }
        bluetooth_processing_mbox_create((char *)dev->name, PROCESS_CONNECT);
        ret = bt_connect_device(addr, dev->cod);
    } else {
        bluetooth_processing_mbox_create((char *)dev->name, PROCESS_DISCONNECT);
        ret = bt_disconnect_device(addr, dev->cod);
    }
    if(-1 == ret) {
        bluetooth_processing_mbox_update();
    }
}

static void bluetooth_paired_list_btn_action(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    bt_paired_dev_t * dev = (bt_paired_dev_t *)lv_obj_get_user_data(btn).user_data;
    uint8_t state = dev->profile_status[PROFILE_CONNECTION];
    if(ext->mbox) return;

    uint16_t txtId = 0;
    if(PROFILE_STATE_CONNECTED == state) {
        txtId = WATCH_TEXT_ID_DISCONNECT;
    } else {
        txtId = WATCH_TEXT_ID_CONNECT;
    }

    lv_obj_t * par = lv_obj_get_parent(lv_obj_get_parent(ext->dev_list));
    lv_obj_t * bg = lv_img_create(par, NULL);
    lv_img_set_src(bg, watch_get_bg());
    lv_obj_set_click(bg, true);
    lv_obj_t * back_img = lv_img_create(bg, NULL);
    lv_img_set_src(back_img, ICON_ALBUM_BACK);
    lv_obj_set_click(back_img, true);
    lv_watch_set_free_num(back_img, 2);
    lv_obj_set_event_cb(back_img, bluetooth_back_img_event_cb);
    lv_obj_t * label = lv_label_create(bg, NULL);
    lv_label_set_text(label, (char *)dev->name);
    lv_label_set_long_mode(label, LV_LABEL_LONG_SROLL_CIRC);
    lv_label_set_align(label, LV_LABEL_ALIGN_CENTER);
    lv_obj_set_width(label, lv_obj_get_width(bg) - lv_obj_get_width(back_img));
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20_gray);
    if(lv_obj_get_base_dir(par) == LV_BIDI_DIR_RTL) {
        lv_obj_align(back_img, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
        lv_img_set_angle(back_img, 1800);
        lv_obj_align(label, back_img, LV_ALIGN_OUT_LEFT_MID, -(LV_HOR_RES / 2  - lv_obj_get_width(back_img) - lv_obj_get_width(label) / 2), 0);
    } else {
        lv_obj_align(back_img, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
        lv_obj_align(label, back_img, LV_ALIGN_OUT_RIGHT_MID, -lv_obj_get_width(back_img) / 4, 0);
    }

    lv_obj_t * btn_label;
    lv_obj_t * con_btn = lv_btn_create(bg, NULL);
    lv_obj_set_size(con_btn, LV_HOR_RES, LV_VER_RES / 8);
    lv_obj_align(con_btn, bg, LV_ALIGN_IN_TOP_MID, 0, lv_obj_get_height(back_img));
    lv_obj_add_style(con_btn, LV_BTN_PART_MAIN, &(ext->btn_rel));
    lv_obj_set_style_local_pad_left(con_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 10);
    lv_obj_set_style_local_pad_right(con_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 10);
    lv_obj_set_event_cb(con_btn, bluetooth_process_btn_action);
    lv_btn_set_layout(con_btn, LV_LAYOUT_ROW_MID);
    lv_watch_set_free_num(con_btn, lv_list_get_btn_index(ext->dev_list, btn));
    lv_watch_set_free_ptr(con_btn, lv_obj_get_user_data(btn).user_data);
    btn_label = lv_label_create(con_btn, NULL);
    lv_obj_add_style(btn_label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_label_set_text_id(btn_label, txtId);
    lv_obj_t * p_btn = lv_btn_create(bg, con_btn);
    lv_obj_align(p_btn, con_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
    btn_label = lv_label_create(p_btn, btn_label);
    lv_label_set_text_id(btn_label, WATCH_TEXT_ID_UNPAIRED);
    lv_watch_set_free_num(p_btn, lv_list_get_btn_index(ext->dev_list, btn));
    lv_watch_set_free_ptr(p_btn, lv_obj_get_user_data(btn).user_data);

    if((dev->cod & COD_TYPE_PHONE) == COD_TYPE_PHONE) {
        lv_obj_set_hidden(con_btn, true);
        lv_obj_align(p_btn, bg, LV_ALIGN_IN_TOP_MID, 0, lv_obj_get_width(back_img));
    }
}

static lv_obj_t * bluetooth_processing_mbox_create(char * name, uint8_t process)
{
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    char str[64];
    lv_obj_t * mbox = lv_msgbox_create(lv_obj_get_parent(ext->dev_list), NULL);
    memset(str, 0, 64);
    if(process == PROCESS_PAIR)
        snprintf(str, 64, "%s\n%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_PAIRING), name);
    else if(process == PROCESS_CONNECT)
        snprintf(str, 64, "%s\n%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_CONNECTION), name);
    else if(process == PROCESS_UNPAIR)
        snprintf(str, 64, "%s\n%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_UNPAIRING), name);
    else if(process == PROCESS_DISCONNECT)
        snprintf(str, 64, "%s\n%s", (char *)lv_lang_get_text(WATCH_TEXT_ID_DISCONNECTING), name);
    lv_msgbox_set_text(mbox, str);
    lv_obj_set_size(mbox, LV_HOR_RES * 2 / 3, LV_VER_RES * 2 / 3);
    lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
    ext->mbox = mbox;
    lv_watch_set_free_num(mbox, process);
    return mbox;
}

static void bluetooth_tip_mbox_create(lv_obj_t * par)
{
    lv_obj_t * mbox = lv_msgbox_create(par, NULL);
    lv_msgbox_set_text(mbox, (char *)lv_lang_get_text(WATCH_TEXT_ID_CONNECTED_ALREADY));
    lv_obj_set_size(mbox, LV_HOR_RES * 2 / 3, LV_VER_RES * 2 / 3);
    lv_obj_realign(mbox);
    lv_msgbox_set_anim_time(mbox, 0);
    lv_msgbox_start_auto_close(mbox, 2000);
}

static void bluetooth_availabel_list_btn_action(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
    if(ext->mbox != NULL) {
        return;
    }
    if(bt_get_headset_connect() || bt_transfer_mbox != NULL) {
        bluetooth_tip_mbox_create(lv_obj_get_parent(ext->dev_list));
        return;
    }

    struct bt_addr addr;
    uint8_t index = lv_obj_get_user_data(btn).user_num;
    struct bt_event_inquiry * scan_dev = bt_get_scan_dev(index);
    printf("bt find bounding node cod = %x\n\n", scan_dev->cod);

    memcpy(addr.bytes, scan_dev->addr, 6);
    int32_t ret = bt_bonding_device(addr, scan_dev->cod);

    lv_obj_t * mbox = bluetooth_processing_mbox_create((char *)scan_dev->name, 0);
    lv_watch_set_free_ptr(mbox, scan_dev);

    if(ret != 0) {
        bluetooth_processing_mbox_update();
    }
}

static void bluetooth_clean_scan_list(void)
{
    bt_clean_scan_list();
    bluetooth_update_scan_label_show();
}

static void bluetooth_refresh_btn_action(lv_obj_t * btn, lv_event_t e)
{
    if(LV_EVENT_CLICKED != e) return;
    bluetooth_cancel_inquiry();
    bluetooth_clean_scan_list();
    watch_set_suspend_enable(false, ACT_ID_BLUETOOTH, 0);
    int8_t ret = bt_inquiry_device();
    if(ret == 0) {
        lv_bluetooth_obj_ext_t * ext = bluetooth_get_ext();
        if(ext->preload != NULL) {
            lv_obj_del(ext->preload);
            ext->preload = NULL;
        }
        lv_obj_set_hidden(lv_obj_get_child(btn, NULL), true);
        lv_btn_set_state(btn, LV_BTN_STATE_DISABLED);

        lv_obj_t * preload = lv_spinner_create(btn, NULL);
        lv_obj_set_size(preload, 25, 25);
        lv_obj_set_style_local_line_color(preload, LV_SPINNER_PART_BG, LV_STATE_DEFAULT, LV_COLOR_WHITE);
        lv_obj_set_style_local_line_width(preload, LV_SPINNER_PART_BG, LV_STATE_DEFAULT, 2);
        lv_obj_set_style_local_line_rounded(preload, LV_SPINNER_PART_BG, LV_STATE_DEFAULT, 1);
        lv_obj_set_style_local_line_color(preload, LV_SPINNER_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GRAY);
        lv_obj_set_style_local_line_width(preload, LV_SPINNER_PART_INDIC, LV_STATE_DEFAULT, 2);
        lv_spinner_set_type(preload, LV_SPINNER_TYPE_SPINNING_ARC);
        lv_spinner_set_spin_time(preload, 2000);
        lv_obj_align(preload, NULL, LV_ALIGN_IN_RIGHT_MID, -15, 0);
        ext->preload = preload;
    }
}

static lv_obj_t * bluetooth_dev_list_add(lv_obj_t * list, uint8_t state, char * name, lv_event_cb_t rel_action, uint32_t cod_type)
{
    lv_bluetooth_obj_ext_t  * b_ext = bluetooth_get_ext();
    lv_obj_t * btn;
    btn = lv_btn_create(list, NULL);
    lv_obj_add_style(btn, LV_BTN_PART_MAIN, &(b_ext->btn_rel));
    lv_obj_set_style_local_pad_left(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 5);
    lv_obj_set_style_local_pad_right(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 5);

    /*Save the original signal function because it will be required in `lv_list_btn_signal`*/
    lv_list_set_ancestor_btn_signal(btn);
    lv_page_glue_obj(btn, true);
    lv_obj_add_protect(btn, LV_PROTECT_PRESS_LOST);
    lv_obj_set_signal_cb(btn, lv_list_get_listbtn_signal());
    lv_btn_set_layout(btn, LV_LAYOUT_ROW_MID);
    lv_obj_set_event_cb(btn, rel_action);

    /*Make the size adjustment*/
    lv_obj_t * cont = lv_cont_create(btn, NULL);
    lv_cont_set_fit2(cont, LV_FIT_TIGHT, LV_FIT_TIGHT);
    if(lv_obj_get_base_dir(list) == LV_BIDI_DIR_RTL)
        lv_cont_set_layout(cont, LV_LAYOUT_COLUMN_RIGHT);
    else
        lv_cont_set_layout(cont, LV_LAYOUT_COLUMN_LEFT);
    lv_obj_set_click(cont, false);
    lv_obj_set_style_local_bg_opa(cont, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_0);

    lv_obj_t * label = lv_label_create(cont, NULL);
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &lv_watch_font20);
    lv_obj_set_click(label, false);
    lv_label_set_text(label, name);
    lv_label_set_long_mode(label, LV_LABEL_LONG_SROLL_CIRC);
    lv_coord_t w = lv_obj_get_width(list);
    uint8_t pad_w = w - LV_HOR_RES / 30;
    lv_coord_t pad_bottom = lv_obj_get_style_pad_bottom(label, LV_LABEL_PART_MAIN);
    if(4 > pad_bottom) {
        pad_bottom = 4;
    }
    lv_obj_set_size(btn, pad_w, 2 * lv_obj_get_height(label) + pad_bottom);
    lv_obj_set_width(label, pad_w - 25);
    if(state == PROFILE_STATE_CONNECTED && cod_type == COD_TYPE_HEADSET) {
        lv_obj_t * state_label = lv_label_create(cont, NULL);
        lv_obj_add_style(state_label, LV_LABEL_PART_MAIN, &lv_watch_font20_gray);
        lv_label_set_text_id(state_label, WATCH_TEXT_ID_CONNECTED);
    }
    if(state != PROFILE_STATE_MAX) {
        lv_obj_t * right_label = lv_label_create(btn, NULL);
        lv_obj_set_style_local_text_font(right_label, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_THEME_WATCH_NIGHT_SYMBOL_NORMAL);
        if(lv_obj_get_base_dir(list) == LV_BIDI_DIR_RTL)
            lv_label_set_text(right_label, LV_SYMBOL_LEFT);
        else
            lv_label_set_text(right_label, LV_SYMBOL_RIGHT);
        lv_obj_set_width(right_label, 15);
        lv_obj_set_style_local_pad_inner(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT,
                                         lv_obj_get_width(btn) - lv_obj_get_width(cont) - lv_obj_get_width(right_label) - 10);
    }
    return btn;
}

static nv_watch_bluetooth_t * bluetooth_read_nvm(void)
{
    uint32_t length = sizeof(nv_watch_bluetooth_t);
    nv_watch_bluetooth_t * nvm = (nv_watch_bluetooth_t *)lv_mem_alloc(length);
    if(length != UI_NV_Read_Req(NV_SECTION_UI_BLUETOOTH, 0, length, (uint8_t *)nvm)) {
        printf("read bluetooth from nvm error\n");
        lv_mem_free(nvm);
        return NULL;
    }
    return nvm;
}

#if USE_LV_WATCH_SD_AUTO_MOUNT != 0
void bluetooth_for_mount_destory(void)
{
    printf("%s\n", __FUNCTION__);
    bt_file_receive_cancel();
}
#endif

#endif /*USE_LV_BLUETOOTH*/
